package shared;

import java.io.Serializable;

/**
 * super class Data represents all shared data. Encrypt method are placed here,
 * to make sure all data is encrypted
 */
public class Data implements Serializable {
	private static final int key = 6;

	/**
	 * method to encrypt/decrypt Strings
	 * 
	 * @param cipher
	 * @return encrypted/decrypted cipher
	 */
	public static String xor(String cipher) {
		byte[] bytesBuf = cipher.getBytes();
		for (int i = 0; i < bytesBuf.length; i++) {
			bytesBuf[i] = (byte) (bytesBuf[i] ^ key);
		}
		return new String(bytesBuf);
	}

	/**
	 * method to encrypt/decrypt doubles
	 * 
	 * @param cipher
	 * @return encrypted/decrypted cipher
	 */
	public static double xor(double cipher) {

		return Double.longBitsToDouble(Double.doubleToRawLongBits(cipher)
				^ Double.doubleToRawLongBits(key));
	}

	/**
	 * method to encrypt/decrypt ints
	 * 
	 * @param cipher
	 * @return encrypted/decrypted cipher
	 */
	public static int xor(int cipher) {
		return cipher ^ key;
	}
}